<?php 
/* 
Template Name: user manager
*/
?>
<?php ?>
<?php 
           global $id_sai_email;$status_pass;
            global $current_user;
            get_currentuserinfo();
           // var_dump($current_user);
          //  echo  $current_user->roles[0];

 if ( !is_user_logged_in() ) 
    {
      ?>

        
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
elseif (is_user_logged_in() )  
 { 
get_header(); 
    if ( ( $current_user->roles[0] == 'editor') or ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
        ?>

        
              <?php wp_die( __( 'Vui lòng  quay lai trang chủ ! ' ) ); ?>
       
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'editor') or( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {

        //echo 'hoang phuc duoc phep';
     ?>

<div id="content_nano_two" class="clearfix">
<a  href='<?php bloginfo('url');?>/them-nguoi-dung'> <button id='them_moi_nhieu' class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"  role="button" aria-disabled="false">
                      <span >Thêm mới user</span><!-- class="ui-button-text" -->
                      </button></a>		
<?php 
                        $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
                        // WHERE post_type='post'";
    ?>            

                <div id='div_form'>
                      <form action='#' method="get" >
                                      <table class="wp-list-table widefat fixed users" cellspacing="0">
                                        <thead>
                                          <tr>
                                            <th scope="col" id="cb"  style=""> </th>
                                            <th scope="col" id="username"  style="width: 170px;">
                                                <span>Tài khoản</span>
                                            </th>
                                            <th scope="col" id="name"  style="width: 174px;">
                                                <span>Tên người dùng</span>
                                            </th>
                                            <th scope="col" id="email" style="width: 200px;">
                                                  <span>E-mail</span>
                                            </th>
                                                <th scope="col" id="role"  style="width: 129px;"></th>
                                          </tr>
                                        </thead>

                                        <tfoot>
                                        <tr>
                                          <th scope="col" style=""> </th>
                                          <th scope="col"  style="">
                                              <span>Tài khoản</span>
                                          </th>
                                          <th scope="col"  style="">
                                              <span>Tên người dùng</span>
                                          </th>
                                          <th scope="col"  style="">
                                              <span>E-mail</span>
                                          </th>
                                          <th scope="col"  style=""></th>
                                        </tr>
                                        </tfoot>

                                        <tbody id="the-list" data-wp-lists="list:user">

                                      <?php 
                                         $rows = $wpdb->get_results($query_user);
                                        foreach($rows as $post)
                                         
                                        {

                                      ?>
                                        <tr id="user-<?php $post->ID; ?>" class="alternate">

                                          <th scope="row" class="check-column">
                                            <label class="screen-reader-text" for="cb-select-1"></label>
                                          </th>

                                          <td class="username column-username" style='vertical-align: inherit;'>
                                            <!-- 
                                            <img alt="" 
                                            src="<?php echo get_bloginfo('template_directory').'/images/avanta_user.png';?>" class="avatar avatar-32 photo" height="32" width="32"> 
                                          -->

                                            <strong>
                                              <?php echo $post->user_nicename;?>
                                            </strong>
                                           
                                           

                                          </td>

                                          <td class="name column-name"><?php echo $post->display_name;?> </td>
                                            <td class="email column-email">
                                              <a href="mailto:<?php echo $post->user_email; ?>" title="E-mail: <?php echo $post->user_email; ?>"><?php echo $post->user_email; ?></a>
                                            </td>
                                            <!-- <td class="role column-role"><?php echo $post->user_registered; ?></td> -->
                                            <td class="posts column-posts num">
                                              <form><fieldset></fieldset></form>
                                              <div style="display: inline-block;width: 300px;padding-top: 8px;">
                                                  <div style='float:left;'>
                                                          <form action='<?php bloginfo('url');?>/edit-user' method='POST'>
                                                            <fieldset>
                                                              <input type="hidden" name="sua_edit" id="sua_edit" value='<?php echo $post->ID; ?>'>
                                                              <input type="submit" name="sua_<?php echo $post->ID;?>" id="sua_<?php echo $post->ID;?>" value='Sửa'/>
                                                            </fieldset>
                                                        </form>
                                                  </div>
                                                  
                                                  <div style='float:left;'>
                                                    <form id='xoa-form' method='POST'>
                                                      <fieldset>
                                                        <nav role="tab">
                                                          <ul>
                                                            <li iduser='<?php echo $post->ID; ?>'>
                                                              <input type="submit" name="xoa" id="xoa" value='Xóa' onclick="if (! confirm('Bạn không xóa máy này ? chọn Click OK . Nếu bạn muốn Xóa chọn Cancel')) return false;"/>
                                                            </li>
                                                          </ul>
                                                        </nav>
                                                      
                                                      </fieldset>
                                                  </form>
                                                </div><!-- style='float:left;' -->

                                                </div><!-- style="display: inline-block;width: 300px;padding-top: 8px;" -->
                                            </td>

                                            
                                            </td>
                                       </tr><!-- id="user-xyz" class="alternate" -->

                                      <?php } // end foreach($rows as $post) ?>


                                       </tbody>
                                      </table>
             </form>
              <div id="sent">Sucess</div>
              <div id='phuc'></div> 

<script type="text/javascript">
     jQuery(document).ready(function(){

          $("nav[role='tab'] ul li").click(function() {
          var iduser = $(this).attr("iduser");
          var UrL  = "<?php bloginfo('url');?>/quan-li-nguoi-dung";
         // alert(UrL);
          //alert(id_xoa);
          //alert('hoangphuc');
          //return;

          $.ajax({
                  url:"<?php bloginfo('url');?>/processing-delete-user",
                    type:"POST",
                    data: {iduser:iduser},
                    success: function(data)
                    {
                      alert(data);
                      document.location.href='<?php bloginfo('url');?>/quan-li-nguoi-dung';
                     // document.location.reload('<?php bloginfo('url');?>/quan-li-nguoi-dung');
                      //alert('Xóa máy thành công');
                    //$('#sent').show();
                  //  $('#phuc').html(data);
                  //  $('#phuc').show();
                     }
              });
          });
            
        })
    </script>
    
</div>
</div><!-- id="content_nano_two" -->

<?php
   } //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) )  
  ?>
		
<?php get_footer(); ?>